#include "nextinfowidget.h"

NextInfoWidget::NextInfoWidget(QWidget *parent) :
    QWidget(parent)
{
    m_curBallList.clear();

}

void NextInfoWidget::setNextInfoBall(QList < CBall > balllist)
{
    m_curBallList = balllist;
}


void NextInfoWidget::paintEvent(QPaintEvent *)
{
    if (m_curBallList.count() == 0 )
    {
        return ;
    }

    QPainter painter(this);

    float everWidth = 1.0 * this->rect().width() / m_curBallList.count();

    QRect tmpRect(this->rect().x(), this->rect().y(), this->rect().width() - 1, this->rect().height() - 1);

    painter.drawRect(tmpRect);

    for (int i = 1; i < m_curBallList.count() ; i ++)
    {
        float x = this->rect().left() + i * everWidth;
        painter.drawLine(x, this->rect().top(), x, this->rect().bottom() );
    }

    for (int i = 0; i < m_curBallList.count(); i++)
    {
        float x = this->rect().left() + i * everWidth;
        m_curBallList[i].drawBall(painter,
                                   QRectF(x, this->rect().top(),
                                          everWidth, this->rect().height()));
    }

}
